package com.tuanda.app.customviewdemo.cavans;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by LiDongduo on 2018/9/19.
 */
public class DrawPointView extends View {

    private Paint mPaint;

    public DrawPointView(Context context) {
        this(context,null);
    }

    public DrawPointView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public DrawPointView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        // 点的大小宽度
        mPaint.setStrokeWidth(30);
        mPaint.setColor(Color.GREEN);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPoint(50,50,mPaint);
        mPaint.setStrokeCap(Paint.Cap.SQUARE);
        canvas.drawPoint(100,50,mPaint);

        mPaint.setStrokeCap(Paint.Cap.ROUND);
        // 设置坐标数组
        float[] pts = new float[]{0,10,
                150,50,
                150,100,
                200,50,
                200,100};
        // count 为剩余数组长度
        canvas.drawPoints(pts,2,8,mPaint);
    }
}
